package org.example.struct.array;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author liyishan
 * @date 2023/12/5 10:41
 * @apiNote
 */

public class Test00349Intersection {


    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set = new HashSet<>();
        for(int num : nums1){
            set.add(num);
        }
        List<Integer> res = new ArrayList<>();
        int i = 0;
        for(int num:nums2){
            if(set.contains(num) && !res.contains(num)){
                res.add(num);
            }
        }
        int[] resArr = new int[res.size()];
        for(int j = 0; j < res.size(); j++){
            resArr[j] = res.get(j);
        }
        return resArr;
    }
}
